//
//  Person.m
//  OC02_方法
//
//  Created by dllo on 15/12/1.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "Person.h"

@implementation Person

- (void)information {
    NSLog(@"name:%@, age:%ld, sex:%@", _name, _age, _sex);
}



/** 初始化方法 */
- (instancetype)initWithName:(NSString *)name {
    
    /** self 关键子: 指当前类的对象 */
    self = [super init];
    if (self) {
        _name = name;
    }
    return self;
}



- (instancetype)initWithName:(NSString *)name
                         age:(NSInteger)age
                         sex:(NSString *)sex {
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
        _sex = sex;
    }
    return self;
}


/** 便利构造器方法(是类方法, 类调用此方法) */
+ (instancetype)personWithName:(NSString *)name
                           age:(NSInteger)age
                           sex:(NSString *)sex {
    Person *per = [[Person alloc] initWithName:name age:age sex:sex];
    
    return per;    
}

+ (instancetype)person {
    Person *per = [[Person alloc] init];
    return per;
}







/** setter方法: 目的, 给一个实例变量赋值 */
- (void)setName:(NSString *)name {
    
    _name = name;

}
/** getter方法: 目的, 取出一个实例变量的值 */
- (NSString *)name {
    
    return _name;
}


- (void)setAge:(NSInteger)age {
    _age = age;
}
- (NSInteger)age {
    return _age;
}


- (void)setSex:(NSString *)sex {
    _sex = sex;
}
- (NSString *)sex {
    return _sex;
}

- (void)study {
    NSLog(@"我要学习");
}


@end

